package cn.liutao.auth.api;

import cn.liutao.auth.entity.param.RestPwdParam;
import cn.liutao.auth.service.UserService;
import cn.liutao.common.utils.AuthUtils;
import cn.liutao.common.utils.ServletUtils;
import cn.liutao.common.utils.ValidUtil;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.groups.Default;
import java.io.IOException;
/**
 * @author liutao
 * @Description 重置密码
 * @date 2023/10/30 19:33
 * @Version 1.0
 */
@WebServlet("/user/resetPwd")
public class ResetPasswordServlet  extends HttpServlet {

    private UserService userService;

    @Override
    public void init() {
        userService = UserService.getInstance();
    }

    /**
     * 重置密码接口
     * @param req
     * @param resp
     * @throws ServletException
     * @throws IOException
     */
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        AuthUtils.isAdmin();
        RestPwdParam restPwdParam = ServletUtils.getBodyParam(req, RestPwdParam.class);
        ValidUtil.validated(restPwdParam, Default.class);
        userService.resetPassword(restPwdParam);
        ServletUtils.ok(resp,"重置成功");
    }
}
